/*
day278
2020.6.1
*/
#include<iostream>
#include<vector>
using namespace std;


struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    TreeNode* constructFromPrePost(vector<int>& pre, vector<int>& post) {
		int position=0;
		return help(pre,position,post,0,post.size()-1);
    }
    
    TreeNode* help(vector<int>& pre,int &position,vector<int>& post,int left,int right)
    {
    	if(position>=pre.size() || left>right)
    	{
    		return nullptr;
		}
		
		TreeNode *root=new TreeNode(pre[position]);
		
		if(++position>=pre.size())
		{
			return root;
		 } 
		int tem=left;
		int next=pre[position];
		while(post[tem]!=next)
		{
			tem++;
		}
		
		root->left=help(pre,position,post,left,tem);
		root->right=help(pre,position,post,tem+1,right-1);
		
		return root;
	}
};

int main()
{
	return 0;
}
